package com.zxy.ziems.server.production.controller;

import com.zxy.btp.security.annotation.IgnoreLogin;
import com.zxy.ziems.server.production.pojo.param.ProductionTableParam;
import com.zxy.ziems.server.production.service.CustXyhCompletercvService;
import com.zxy.ziems.server.production.service.CustXyhCompleterptService;
import com.zxy.ziems.server.production.service.CustXyhShipService;
import com.zxy.ziems.server.production.task.ProductionDataSyncTask;
import com.zxy.ziems.server.vo.ChartVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.Year;

/**
 * 产量信息
 *
 * @Copyright (C),
 * @ClassName: CustXyhCompletercvController
 * @Author: yanzhiwei
 * @Description:
 * @Date: 2024/5/13 16:29
 */
@RestController
@Validated
@RequestMapping("/api/producion/completercv")
public class CustXyhCompletercvController {


    private ProductionDataSyncTask productionDataSyncTask;


    /**
     * 产量统计(稼动率，月看板)
     *
     * @return
     */
    @GetMapping("/dateMonthRateCount")
    public ChartVo dateMonthRateCount() {
        Integer currentYear = Year.now().getValue();

        return service.dateMonthRateCount();
    }

    /**
     * 产量统计
     *
     * @param productionTableParam
     * @return
     */
    @GetMapping("/dateCount")
    public ChartVo typeCount(@Validated(value = ProductionTableParam.Select.class) ProductionTableParam productionTableParam) {
        return service.CustXyhCompletercvDataCompareOld(productionTableParam.getStart(), productionTableParam.getEnd(), productionTableParam.getQueryType());
    }

    /**
     * 稼动率（生产数据报表）
     *
     * @param productionTableParam
     * @return
     */
    @GetMapping("/dateRateCount")
    public ChartVo dateRateCount(@Validated(value = ProductionTableParam.Select.class) ProductionTableParam productionTableParam) {
        return service.dateRateCount(productionTableParam.getStart(), productionTableParam.getEnd(), productionTableParam.getQueryType());
    }


    /**
     * 产量统计(月看板)
     *
     * @return
     */
    @GetMapping("/dateMonthCount")
    public ChartVo dateMonthCount() {
        return service.CustXyhCompletercvDataCompare();
    }

    /**
     * 出货量统计(月看板)
     *
     * @return
     */
    @GetMapping("/dateHisCount")
    public ChartVo dateHisCount() {

        return custXyhShipService.CustXyhShipDataCompareMonth();
    }


    @GetMapping("/synData")
    @IgnoreLogin
    public boolean synData() {
        custXyhCompleterptService.synData(LocalDate.now());
        return true;
    }


    private CustXyhCompletercvService service;

    @Autowired
    private CustXyhCompleterptService custXyhCompleterptService;

    @Autowired
    public void setService(CustXyhCompletercvService custXyhCompletercvService) {
        this.service = custXyhCompletercvService;
    }

    private CustXyhShipService custXyhShipService;

    @Autowired
    public void setService(CustXyhShipService custXyhShipService) {
        this.custXyhShipService = custXyhShipService;
    }

    @Autowired
    public void setProductionDataSyncTask(ProductionDataSyncTask productionDataSyncTask) {
        this.productionDataSyncTask = productionDataSyncTask;
    }
}
